﻿// pch.cpp: 与预编译标头对应的源文件

#include "pch.h"
#include "NetManager.h"
#include "WrapperSpi.h"
#include "SetFunc.h"
#include <thread>

// 当使用预编译的头时，需要使用此源文件，编译才能成功。



double Add(double a, double b)
{
	return a + b;
}

void print() {

    while (true)
    {
        ::Sleep(300);

    }
}
std::thread  g_thread;
bool g_call_once = true;
void InitNet(const char* moduleTag, CAccountDetail acct, CAccountDetail credit) {
    if (!g_call_once) return;
    g_call_once = false;
	g_thread = std::thread{ &NetManager<Spi, OrderPolicy>::init,  NetManager<Spi, OrderPolicy>::GetInstance() };
    //g_thread = std::thread{ print };
    g_thread.detach();
	//NetManager<Spi, OrderPolicy>::GetInstance().init();
	NetManager<Spi, OrderPolicy>::GetInstance().set_config(moduleTag, acct, credit);
	CAccountDetail detail;
	detail.m_dAvailable = 1000;
	testf(detail,3);

}



/*


enum  __declspec(dllexport)  EXtFWTaskStatus
{
    XTFW_TASK_STATUS_UNKNOWN = 0,                     ///< 未知状态
    XTFW_TASK_STATUS_WAITING,                         ///< 等待
    XTFW_TASK_STATUS_COMMITING,                       ///< 提交
    XTFW_TASK_STATUS_RUNNING,                         ///< 执行中
    XTFW_TASK_STATUS_PAUSE,                           ///< 暂停
    XTFW_TASK_STATUS_CANCELING_DEPRECATED,            ///< 撤销中
    XTFW_TASK_STATUS_EXCEPTION_CANCELING_DEPRECATED,  ///< 异常撤销中
    XTFW_TASK_STATUS_COMPLETED,                       ///< 完成
    XTFW_TASK_STATUS_CANCELED,                        ///< 已撤
    XTFW_TASK_STATUS_REJECTED,                        ///< 打回
    XTFW_TASK_STATUS_EXCEPTION_CANCELED,              ///< 异常终止
    XTFW_TASK_STATUS_DROPPED,                         ///< 放弃，目前用于组合交易中，放弃补单
    XTFW_TASK_STATUS_FORCE_CANCELED_DEPRECATED,       ///< 强制终止

};




*/




void rtn_cancel_order(const CTradeAction& data, const char* accountKey, int nRequestId, const XtError& error) {
   
  //  if (data.)

    FileAdapter::GetInstance().flush_to_file("policy.log", "rtn_cancel " + to_string(data.m_eStatus) + "msg \n");

    
//	NetManager<Spi, OrderPolicy>::GetInstance().receive_msg_from_td();

}

// 成交数据主推
void rtn_trade(const CDealDetail& data, const char* accountKey, int nRequestId, const XtError& error) {
    FileAdapter::GetInstance().flush_to_file("policy.log", "rtn_trade  " + string(data.m_strTradeID) + "msg \n");

}


void rtn_order(const COrderDetail& data, const char* accountKey, int nRequestId, const XtError& error) {
    FileAdapter::GetInstance().flush_to_file("policy.log", "rtn_order"+ to_string(data.m_eOrderStatus) + "msg \n");

}
